#include <stdio.h>
#include <stdlib.h>
struct testnum{
    int a;
    int b;
    int num;
    struct testnum* next;
};
struct testnum* newnum(){
    //return (struct testnum *)malloc(sizeof(struct testnum));
    return malloc(sizeof(struct testnum));
}
void print(struct testnum* node, int n){
    //printf("%2d: %5d %5d %5d\n", n, node->a, node->b, node->num);
    if(node->next != NULL){
        printf("%2d: %5d %5d %5d\n", n, node->a, node->b, node->num);
        print(node->next, n+1);
    }
    free(node);
}

int main() 
{
    struct testnum head, *p;
    p = &head;
    head.num=0;
    head.next = NULL;
    //int no=0;
    while(1){
        printf("input a, b >0 \n");
        scanf("%d %d", &p->a, &p->b);
        //no++;
        if(p->a ==0 && p->b == 0){
            printf("wrong num\n");
            p->next = NULL;
            break;
        }
        else if(p->a >0 && p->b > 0){
            p->num += p->a + p->b ;
            p->next = newnum();
            p->next->num = p->num ;
            p = p->next ;
        } 
    }
    print(&head,1);
    printf("head.a= %d",head.a);
    system("PAUSE")  ;                                                                       
    return 0;                                                                
}                                                                            
